package com.hopes.bizz.risk.transfer.bean.vo;

import cn.hutool.core.util.NumberUtil;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.bizz.risk.transfer.constant.RiskConstant;
import com.hopes.bizz.risk.transfer.constant.RiskRequestType;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author lyb
 * @version 1.0
 * @date 2024/2/21 14:38
 */

@Data
public class RiskTransferLogVo {

    /**
     * id
     */
    private Long id;

    /**
     * 批次
     */
    private String batchId;

    /**
     * 请求类型
     */
    private Integer requestType;

    /**
     * 请求时间
     */
    private LocalDateTime requestTime;

    /**
     * 处理状态
     */
    private Integer status;

    /**
     * 批次总条数
     */
    private Integer totalCount;

    /**
     * 批次错误条数
     */
    private Integer errorCount;

    /**
     * orgId
     */
    private Long orgId;

    public String getRequestTypeStr() {
        RiskRequestType riskRequestTypeEnum = RiskRequestType.getRiskRequestTypeByCode(requestType);
        if (Objects.nonNull(riskRequestTypeEnum)) {
            return riskRequestTypeEnum.getName();
        }
        return null;
    }

    public String getStatusStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.report_risk_data_handler_status, status);
    }

    public String getOrgIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_company, orgId);
    }

    public Double getEffectiveRate() {
        if (RiskConstant.RISK_TRANSFER_HANDLER_STATUS_PROCESSING.equals(status)) {
            return null;
        }
        if (totalCount == 0) {
            return 0d;
        }

        if (errorCount == 0) {
            return 100d;
        }
        Integer correctCount = totalCount - errorCount;
        return NumberUtil.div(correctCount, totalCount, 2).doubleValue();
    }
}
